<?php 
define("NEED_AUTH", true);  //需要验证

$nav = array(
	'phpinfo'=>array('m'=>'phpinfo'),
	);



Control::start();
class Control {


	static function start() {
		$m = @$_GET['m'];
		if (!$u) echo View::pageFZF();
		else {
			echo View::pageHead();
			echo $u;
			echo View::pageFoot();
		}
		// echo Control::U(array('m'=>'del','f'=>'cookie'));
		// echo '<br>';
		// print_r(Control::I(array('f','m')));	
		// echo View::pageFZF();
	}

	static function U($param){
		$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?';
		if(is_array($param)){
			foreach ($param as $key => $value) {
				$url = $url.$key.'='.base64_encode($value).'&';
			}
		} else $url = $url.'m='.base64_encode($param);
		return $url;
	}

	private function I($param) {
		$params = array();
		if (!is_array($param)) $params[]=$param;
		else foreach ($param as $val) $params[] = $val;
		foreach ($params as $v) {
			if (!empty($_GET[$v])) $result[$v] = base64_decode($_GET[$v]);
			if (!empty($_POST[$v])) $result[$v] = $_POST[$v];
		}
		return $result;
	}

}

class View {
	//显示404页面
	static function pageFZF(){
		$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'_404';
		return Common::getPageContent($url);
	}
	//网页头部分
	static function pageHead(){
		$head = <<<HEAD
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="Web Manage v0.1">
  <meta name="author" content="beizidream@gmail.com">

<link href="http://cdn.bootcss.com/bootstrap/3.1.1/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="http://cdn.bootcss.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="http://cdn.bootcss.com/html5shiv/3.7.0/html5shiv.min.js"></script>
        <script src="http://cdn.bootcss.com/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
</head>
<body>
HEAD;
		return $head;
	}
	//网页尾部份
	static function pageFoot(){
		$foot = <<<FOOT
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
</body>
</html>
FOOT;
		return $foot;
	}
}
	//生成导航
	static function createNav(){
		$navhtml = <<<NAV
	<nav class="navbar navbar-default" role="navigation">
	<div class="navbar-header">
		 <a class="navbar-brand" href="#">此题无解</a>
	</div>
	<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
		<ul class="nav navbar-nav">
			MAINNAV
		</ul>
		<form class="navbar-form navbar-right" role="search" id="1349797664">
			<div class="form-group">
				<input type="text" class="form-control">
			</div> <button type="submit" class="btn btn-default">Baidu</button>
		</form>
		<ul class="nav navbar-nav navbar-right">
			<li class="dropdown">
				 <a href="#" class="dropdown-toggle" data-toggle="dropdown">Other<strong class="caret"></strong></a>
				<ul class="dropdown-menu">
					<li>
						<a href="#">About Me</a>
					</li>
					<li>
						<a href="#">Another action</a>
					</li>
					<li>
						<a href="#">Something else here</a>
					</li>
					<li class="divider">
					</li>
					<li>
						<a href="#">Separated link</a>
					</li>
				</ul>
			</li>
		</ul>
	</div>
</nav>
NAV;
	//MAINNAV 替换这个
	//<li><a href="#">MENU</a></li>


	}

class Common{
	static function getPageContent($url){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$outstr = curl_exec($ch);
		curl_close($ch);
		return $outstr;
	}
}

?>

